/*
 * Copyright (C) 2010 Konan Technology Inc.
 *
 * This file is part of Dokkaebi.
 *
 * Dokkaebi is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dokkaebi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dokkaebi.  If not, see <http://www.gnu.org/licenses/>.
 *
 * This software uses libraries from the FFmpeg project under the GPLv3.
 */

#define __STDC_CONSTANT_MACROS

extern "C" {
	#include "libavformat\avformat.h"
	#include "libavutil\mathematics.h"
}

class Dokkaebi
{
public:
	/**
	 * Constructor
	 */
	Dokkaebi();

	/**
	 * Destructor
	 */
	~Dokkaebi();

	/**
	 * Open input file.
	 */
	bool OpenFile(const char *filename);

	/**
	 * Close open file
	 */
	bool CloseFile();

	/**
	 * Get next frame in the video stream
	 */
	bool GetNextFrame();

	/**
	 * Write the given AVFrame to a jpeg file
	 */
	bool WriteJpeg();

	/**
	 * Skip given number of frames in the stream
	 */
	bool SkipFrames(int numFrames);

private:
	static const int			INBUF_SIZE = 65536;

	int							m_videoStream;
	AVFormatContext				*m_pFormatCtx;	
	AVCodecContext				*m_pCodecCtx;
	AVFrame						*m_pFrame;
	
	AVCodecContext				*m_pOCodecCtx;
	AVCodec						*m_pOCodec;
	uint8_t						*m_imgBuffer;
	int							m_imgBufferSize;

	/**
	 * Load proc addresses from DLLs
	 */
	bool GetProcAddresses();
	
	/**
	 * Initialize Jpeg encoder
	 */
	bool InitJpegEncoder();

	/**
	 * Open video stream from file
	 */
	bool OpenVideoStream();

	/**
	 * Find and open codec for the given codec context
	 */
	bool OpenCodec();
};
